//
//  EmoticonPackage.swift
//  表情键盘
//
//  Created by 陈恒均 on 2018/2/23.
//  Copyright © 2018年 陈恒均. All rights reserved.
//

import UIKit

class EmoticonPackage: NSObject {
    var emoticons : [Emoticon] = [Emoticon]()
    
    init(idendifi : String) {
        
        super.init()
        if idendifi == "" {
            addaddEmptyEmoticon(isRecently: true)
            return
        }
        
        let plistPath = Bundle.main.path(forResource:  "\(idendifi)/info.plist", ofType: nil, inDirectory: "Emoticons.bundle") ?? ""

        let array = NSArray(contentsOfFile: plistPath)! as! [[String : String]]
        
        
        var index = 0
        for var dict in array {
            if let png = dict["png"]
            {
                dict["png"] = idendifi + "/" + png
            }
            emoticons.append(Emoticon(dict : dict))
            index = index + 1
            if index == 20 {
                ///添加删除表情
                emoticons.append(Emoticon(isRomove: true))
                index = 0
            }
            
        }
        //添加空白表情
        addaddEmptyEmoticon(isRecently: false)
    }
    
    //添加空白表情
    private func addaddEmptyEmoticon(isRecently :Bool){
        let count = emoticons.count % 21
        if count == 0 && !isRecently {
            return
        }
        for _ in count..<20 {
            emoticons.append(Emoticon(isEmpty: true))
        }
        emoticons.append(Emoticon(isRomove: true))
 
    }

    
}
